#pragma once

#include "acl/acl.h"
#include <stdio.h>
#include <cassert>
#include <iostream>
#include <chrono>
#include <stdint.h>
#include <fstream>
#include <string>

#define CHECK(err) \
  if(err != ACL_SUCCESS){ \
    std::cout << __FILE__ << ":" << __LINE__ << " " << " occur err" << std::endl; \
  }

static std::uint64_t now() {
  return std::chrono::duration_cast<std::chrono::milliseconds>
    (std::chrono::high_resolution_clock::now().time_since_epoch()).count();
}

static void dumpbin(void *acl_mem, size_t sz, const std::string &path) {
  char * buf = new char[sz];
  CHECK(aclrtMemcpy
    (buf, sz, acl_mem, sz, aclrtMemcpyKind::ACL_MEMCPY_DEVICE_TO_HOST))
  std::ofstream ofs;
  ofs.open(path, std::ios::out | std::ios::trunc | std::ios::binary);
  ofs.write((const char *)buf, sz);
  printf("# dump %s\n", path.c_str());
}

#define DIV_UP(size, align_size) (((size) + (align_size) - 1) / (align_size))

struct Case{
  int m;
  int n;
  int k;
  int loop;
  float avg_latency;
};